<?php
	class AnalyticsController extends AppController {
		public $uses = array('FavouritesCount', 'RetweetsCount', 'TweetsCount', 'FollowersCount');

		function index() {

			/* Query the database for the last 7 records, 
			for both favourites and retweets */

			$accID = $this->Auth->user('current_account');

			$favs = $this->FavouritesCount->find('all', array(
			'conditions' => array('account_id' => $accID),
			'limit' => '24',
			'fields' => 'count',
			'order' => 'query_time DESC'
			));

			$retweets = $this->RetweetsCount->find('all', array(
			'conditions' => array('account_id' => $accID),
			'limit' => '24',
			'fields' => 'count',
			'order' => 'query_time DESC'
			));

			$tweets = $this->TweetsCount->find('all', array(
			'conditions' => array('account_id' => $accID),
			'limit' => '24',
			'fields' => 'count',
			'order' => 'query_time DESC'
			));

			$followers = $this->FollowersCount->find('all', array(
			'conditions' => array('account_id' => $accID),
			'limit' => '24',
			'fields' => 'count',
			'order' => 'query_time DESC'
			));

			$follow_daily = $this->FollowersCount->getDaily($accID);

			$status = true;

			if(count($favs) < 24 || count($retweets) < 24 || count($tweets) < 24 || count($followers) < 24 /*count($follow_daily) < 6*/) {
				$status = false;
			}

			/* Make the data available for the view */

			$data = array(
				'favs' => $favs,
				'retweets' => $retweets,
				'tweets' => $tweets,
				'followers' => $followers,
				'follow_daily' => $follow_daily,
				'status' => $status
				);

			$this->set($data);
		}


	}